/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.luedinski.objects;

import java.util.Iterator;

/**
 *
 * @author lueder
 */
public class ScheduledRoute extends Route {

    private Time departure;

    public ScheduledRoute(Route route, Time departure) {
        super(route.id, route.name, route.velocity, route.route, route.origin, route.destination);
        this.departure = departure;
    }

    public Time getDeparture() {
        return departure;
    }

    public void setDeparture(Time departure) {
        this.departure = departure;
    }

    @Override
    public String toString() {
        return departure.getTime() + ": " + super.toString();
    }
    
     public String toString(Station s) {
        return getDepartureTime(s).getTime() + ": " + super.toString();
     }
    
    
    public Time getDepartureTime(Station s){
        Iterator<Station> stations = route.vertexSet().iterator();
        Time arrival = departure;
        double distance = 0;
        Station actual = null, prev=null;
        do {
            actual = stations.next();
            if(!actual.equals(origin)){
                distance += route.getEdgeWeight(route.getEdge(prev, actual));
            }
            prev = actual;
            
        }while(stations.hasNext() && !actual.equals(s));
        arrival.addMinutes((int)Math.round(distance / velocity * 60));
        return arrival;
    }
}
